VERSION 5.00
Begin VB.Form frmTimeBills 
   ClientHeight    =   3030
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   10500
   LinkTopic       =   "Form1"
   ScaleHeight     =   3030
   ScaleWidth      =   10500
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtEndDate 
      Height          =   285
      Index           =   2
      Left            =   5520
      TabIndex        =   30
      Top             =   1920
      Width           =   1335
   End
   Begin VB.TextBox txtEndDate 
      Height          =   285
      Index           =   1
      Left            =   5520
      TabIndex        =   29
      Top             =   1560
      Width           =   1335
   End
   Begin VB.TextBox txtEndDate 
      Height          =   285
      Index           =   0
      Left            =   5520
      TabIndex        =   28
      Top             =   1200
      Width           =   1335
   End
   Begin VB.ComboBox lstCustomers 
      Height          =   315
      Index           =   2
      Left            =   8400
      Style           =   2  'Dropdown List
      TabIndex        =   27
      Top             =   1920
      Width           =   1935
   End
   Begin VB.ComboBox lstCustomers 
      Height          =   315
      Index           =   1
      Left            =   8400
      Style           =   2  'Dropdown List
      TabIndex        =   26
      Top             =   1560
      Width           =   1935
   End
   Begin VB.TextBox txtStartDate 
      Height          =   285
      Index           =   2
      Left            =   6960
      TabIndex        =   25
      Top             =   1920
      Width           =   1335
   End
   Begin VB.TextBox txtStartDate 
      Height          =   285
      Index           =   1
      Left            =   6960
      TabIndex        =   24
      Top             =   1560
      Width           =   1335
   End
   Begin VB.TextBox txtStartDate 
      Height          =   285
      Index           =   0
      Left            =   6960
      TabIndex        =   23
      Top             =   1200
      Width           =   1335
   End
   Begin VB.ComboBox lstCurrency 
      Height          =   315
      Index           =   2
      ItemData        =   "frmTimeBills.frx":0000
      Left            =   2760
      List            =   "frmTimeBills.frx":0013
      TabIndex        =   14
      Text            =   "NIS"
      Top             =   1920
      Width           =   975
   End
   Begin VB.ComboBox lstCurrency 
      Height          =   315
      Index           =   1
      ItemData        =   "frmTimeBills.frx":0030
      Left            =   2760
      List            =   "frmTimeBills.frx":0043
      TabIndex        =   13
      Text            =   "NIS"
      Top             =   1560
      Width           =   975
   End
   Begin VB.ComboBox lstCurrency 
      Height          =   315
      Index           =   0
      ItemData        =   "frmTimeBills.frx":0060
      Left            =   2760
      List            =   "frmTimeBills.frx":0073
      TabIndex        =   12
      Text            =   "NIS"
      Top             =   1200
      Width           =   975
   End
   Begin VB.TextBox txtItemDescription 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   2
      Left            =   120
      TabIndex        =   11
      Top             =   1920
      Width           =   2535
   End
   Begin VB.TextBox txtUnitPrice 
      Height          =   285
      Index           =   2
      Left            =   3840
      TabIndex        =   10
      Top             =   1920
      Width           =   735
   End
   Begin VB.TextBox txtItemQty 
      BackColor       =   &H00E0E0E0&
      Enabled         =   0   'False
      Height          =   285
      Index           =   2
      Left            =   4680
      TabIndex        =   9
      Top             =   1920
      Width           =   735
   End
   Begin VB.TextBox txtItemDescription 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   1
      Left            =   120
      TabIndex        =   8
      Top             =   1560
      Width           =   2535
   End
   Begin VB.TextBox txtUnitPrice 
      Height          =   285
      Index           =   1
      Left            =   3840
      TabIndex        =   7
      Top             =   1560
      Width           =   735
   End
   Begin VB.TextBox txtItemQty 
      BackColor       =   &H00E0E0E0&
      Enabled         =   0   'False
      Height          =   285
      Index           =   1
      Left            =   4680
      TabIndex        =   6
      Top             =   1560
      Width           =   735
   End
   Begin VB.TextBox txtItemQty 
      BackColor       =   &H00E0E0E0&
      Enabled         =   0   'False
      Height          =   285
      Index           =   0
      Left            =   4680
      TabIndex        =   5
      Top             =   1200
      Width           =   735
   End
   Begin VB.TextBox txtUnitPrice 
      Height          =   285
      Index           =   0
      Left            =   3840
      TabIndex        =   4
      Top             =   1200
      Width           =   735
   End
   Begin VB.TextBox txtItemDescription 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   0
      Left            =   120
      TabIndex        =   3
      Top             =   1200
      Width           =   2535
   End
   Begin VB.ComboBox lstCustomers 
      Height          =   315
      Index           =   0
      Left            =   8400
      Style           =   2  'Dropdown List
      TabIndex        =   2
      Top             =   1200
      Width           =   1935
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "צור חיובי זמן"
      Height          =   375
      Left            =   1320
      TabIndex        =   1
      Top             =   2520
      Width           =   1335
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "יציאה"
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   2520
      Width           =   975
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      Caption         =   "סיום"
      Height          =   255
      Left            =   5640
      TabIndex        =   22
      Top             =   720
      Width           =   615
   End
   Begin VB.Label Label6 
      Alignment       =   1  'Right Justify
      Caption         =   "תאריך התחלה"
      Height          =   255
      Left            =   7080
      TabIndex        =   21
      Top             =   720
      Width           =   1095
   End
   Begin VB.Label Label14 
      Alignment       =   1  'Right Justify
      Caption         =   "מטבע"
      Height          =   255
      Left            =   2880
      TabIndex        =   20
      Top             =   720
      Width           =   615
   End
   Begin VB.Label Label5 
      Alignment       =   1  'Right Justify
      Caption         =   "ש""ע"
      Height          =   255
      Left            =   4680
      TabIndex        =   19
      Top             =   720
      Width           =   615
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      Caption         =   "חיוב לשעה"
      Height          =   375
      Left            =   3720
      TabIndex        =   18
      Top             =   720
      Width           =   855
   End
   Begin VB.Label Label3 
      Alignment       =   1  'Right Justify
      Caption         =   "תיאור הפגישה"
      Height          =   255
      Left            =   720
      TabIndex        =   17
      Top             =   720
      Width           =   1335
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "שם הלקוח:"
      Height          =   255
      Left            =   9240
      TabIndex        =   16
      Top             =   720
      Width           =   1095
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "טופס יצירת חיובי זמן"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   5880
      TabIndex        =   15
      Top             =   120
      Width           =   4455
   End
End
Attribute VB_Name = "frmTimeBills"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Const MOD_NAME = "frmTimeBills."
Dim m_iInvoiceNum As Long


Private Sub cmdCancel_Click()
On Error Resume Next
    Unload Me
End Sub

Private Sub cmdOK_Click()
Const FUNC_NAME = MOD_NAME & "cmdInvoice_Click"
On Error GoTo func_err
    
    Dim iCustomersID As Long
    Dim iTrxCodesID As Long
    Dim V
    Dim objCaspit As CaspitAPI.Caspit
    Dim I As Long
    
    
    For I = 0 To 2
        If lstCustomers(I).ListIndex < 0 Then
            lstCustomers(I).SetFocus
            MyErrMsgBox "חובה לבחור בלקוח"
            Exit Sub
        End If
        If Len(txtUnitPrice(I).Text) = 0 Then
            txtUnitPrice(I).SetFocus
            MyErrMsgBox "חובה להכניס מחיר פריט"
            Exit Sub
        End If
        
        If Len(txtItemDescription(I).Text) = 0 Then
            txtItemDescription(I).SetFocus
            MyErrMsgBox "חובה להכניס תיאור פריט"
            Exit Sub
        End If
        
        If lstCurrency(I).ListIndex < 0 Then
            lstCurrency(I).SetFocus
            MyErrMsgBox "חובה לבחור במטבע"
            Exit Sub
        End If
        
        If Len(txtItemQty(I).Text) = 0 Then
            txtItemQty(I).SetFocus
            MyErrMsgBox "חובה להכניס מחיר פריט"
            Exit Sub
        End If
    Next
    
    Set objCaspit = New CaspitAPI.Caspit
    objCaspit.CaspitPath = g_strCaspitPath
    objCaspit.AccessPath = g_strAccessPath
    objCaspit.DebugMode = g_blnDebug
    objCaspit.BusinessID = g_iBusinessID
    
    Dim InvoiceNum As String
    
    For I = 0 To 2
        V = Split(lstCustomers(I).List(lstCustomers(I).ListIndex), "-")
        
        iCustomersID = V(UBound(V))
        
        objCaspit.CreateTimeBill iCustomersID, txtStartDate(I), txtEndDate(I), _
        txtItemDescription(I), _
        "Appt" & I, InvoiceNum, _
        txtUnitPrice(I).Text, lstCurrency(I).List(lstCurrency(I).ListIndex)
    Next
    
    MyMsgBox "חיובי הזמן נוצרו בהצלחה"
Exit Sub

func_err:
    MyErrMsgBox "Error " & Err.Number & " in " & Err.Source & ": " & Err.Description
    Set objCaspit = Nothing
End Sub


Private Sub Form_Load()
Const FUNC_NAME = MOD_NAME & "Form_Load"
On Error GoTo func_err

    PopulateCustomers
    
    txtStartDate(0) = Format(DateAdd("h", -25, Now), "dd/mm/yy HH:nn")
    txtStartDate(1) = Format(DateAdd("h", -20, Now), "dd/mm/yy HH:nn")
    txtStartDate(2) = Format(DateAdd("h", -3, Now), "dd/mm/yy HH:nn")
    
    txtEndDate(0) = Format(DateAdd("n", 90, txtStartDate(0)), "dd/mm/yy HH:nn")
    txtEndDate(1) = Format(DateAdd("h", 2#, txtStartDate(1)), "dd/mm/yy HH:nn")
    txtEndDate(2) = Format(DateAdd("n", 139, txtStartDate(2)), "dd/mm/yy HH:nn")
    
    txtItemDescription(0) = "פגשת עבודה"
    txtItemDescription(1) = "יעוץ עסקי"
    txtItemDescription(2) = "הכנת תוכנית עבודה"
    
    lstCustomers(0).ListIndex = 0
    lstCustomers(1).ListIndex = 0
    lstCustomers(2).ListIndex = 0
    
    lstCurrency(0).ListIndex = 0
    lstCurrency(1).ListIndex = 0
    lstCurrency(2).ListIndex = 0

Exit Sub

func_err:
    MyErrMsgBox "Error " & Err.Number & " in " & Err.Source & ": " & Err.Description
    Unload Me
End Sub

Private Sub PopulateCustomers()
Const FUNC_NAME = MOD_NAME & "PopulateCustomers"
On Error GoTo func_err
    
    Dim V As Variant
    Dim S As String
    Dim I As Long
    
    Dim objCaspit As CaspitAPI.Caspit
    Dim objCustomer As CaspitAPI.Customer
    
    Set objCaspit = New CaspitAPI.Caspit
    
    objCaspit.CaspitPath = g_strCaspitPath
    objCaspit.AccessPath = g_strAccessPath
    objCaspit.DebugMode = g_blnDebug
    objCaspit.BusinessID = g_iBusinessID
    
    'We could get the information in XML form
    S = objCaspit.GetCustomersXML()
    
    'or in an array
    V = objCaspit.GetCustomers()
    
    Set objCaspit = Nothing
    
    If IsEmpty(V) Then Exit Sub
    
    If UBound(V) < 0 Then
        Err.Raise 1040, "", "יש ליצור לקוחות לפני שיוצרים חשבונית"
    End If
    
    'Skip לקוח מזדמן
    For I = 0 To UBound(V)
        Set objCustomer = V(I)
        If objCustomer.CustomersID > 2 Then
            Call lstCustomers(0).AddItem(objCustomer.BusinessName & " - " & objCustomer.CustomersID)
            Call lstCustomers(1).AddItem(objCustomer.BusinessName & " - " & objCustomer.CustomersID)
            Call lstCustomers(2).AddItem(objCustomer.BusinessName & " - " & objCustomer.CustomersID)
        End If
    Next

Exit Sub

func_err:
    Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
    Set objCaspit = Nothing
End Sub


Private Sub lstCustomers_Change(Index As Integer)
    Dim V
    Dim objCaspit As CaspitAPI.Caspit
    Dim objCustomer As CaspitAPI.Customer
    Dim iCustomersID As Long
    
    Set objCaspit = New CaspitAPI.Caspit
    objCaspit.CaspitPath = g_strCaspitPath
    objCaspit.AccessPath = g_strAccessPath
    objCaspit.DebugMode = g_blnDebug
    objCaspit.BusinessID = g_iBusinessID
    
    V = Split(lstCustomers(Index).List(lstCustomers(Index).ListIndex), "-")
    iCustomersID = V(UBound(V))
    
    Set objCustomer = objCaspit.GetCustomerByID(CLng(iCustomersID))
    
    txtUnitPrice(Index) = objCustomer.Charge
    lstCurrency(Index).Text = objCustomer.ChargeCurrency
End Sub

Private Sub lstCustomers_LostFocus(Index As Integer)
    lstCustomers_Change Index
End Sub

Private Sub txtEndDate_Change(Index As Integer)
    If IsDate(txtStartDate(Index)) And IsDate(txtEndDate(Index)) Then
        txtItemQty(Index) = Round(DateDiff("n", txtStartDate(Index), txtEndDate(Index)) / 60, 1)
    End If
End Sub

Private Sub txtStartDate_Change(Index As Integer)
    If IsDate(txtStartDate(Index)) And IsDate(txtEndDate(Index)) Then
        txtItemQty(Index) = DateDiff("n", txtStartDate(Index), txtEndDate(Index)) / 60
    End If
End Sub


